<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var student = function () {
            var age = 0;
            return {
                getAge: function () {
                    return age;
                },
                setAge: function (value) {
                    if (!isNaN(value) && value >= 0 && value <= 150) {
                        age = value;
                    } else {
                        throw "年龄必须是0-150之间的数字。";
                    }
                }
            }
        }();
        console.log(student.age);
        student.setAge(-18);
        console.log(student.getAge());
    </script>
</body>

</html>